Skip to content

feat(Slider): add support for custom tooltip content#12531

Open
kmcfaul wants to merge 4 commits into
patternfly:mainfrom
kmcfaul:slider-custom-tooltip
Open

feat(Slider): add support for custom tooltip content#12531
kmcfaul wants to merge 4 commits into
patternfly:mainfrom
kmcfaul:slider-custom-tooltip

Conversation

@kmcfaul

@kmcfaul kmcfaul commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What: Closes #12160

  • Adds tooltipContent, which overrides the default behavior of the current value for a custom tooltip
  • Adds example & test

Summary by CodeRabbit

  • New Features
    • Added thumbAriaValueText and tooltipContent to customize slider thumb accessibility text and tooltip text.
    • Added an example demonstrating a custom, step-based tooltip with dynamic labels.
  • Documentation
    • Updated Slider docs with a “Custom step tooltip” section explaining tooltipContent, thumbAriaValueText, and recommended tooltipProps.
  • Bug Fixes
    • Tooltip and thumb aria-valuetext now use the custom values when provided, falling back to the value-derived text.
  • Tests
    • Added coverage for hover tooltip rendering and aria-valuetext behavior with the new props.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4c789189-b9e8-4d99-8a4f-608dd63a1063

📥 Commits

Reviewing files that changed from the base of the PR and between b1d6f96 and 3f37ebc.

📒 Files selected for processing (1)
  • packages/react-core/src/components/Slider/examples/Slider.md

Walkthrough

Adds optional tooltipContent and thumbAriaValueText props to Slider. Tooltip and thumb aria text use these overrides when provided, with tests, documentation, and a custom step tooltip example added.

Changes

Slider Custom Tooltip

Layer / File(s) Summary
Prop API and render logic
packages/react-core/src/components/Slider/Slider.tsx
SliderProps gains tooltipContent?: React.ReactNode and thumbAriaValueText?: string; the component uses them to override tooltip content and aria-valuetext when provided.
Validation and usage example
packages/react-core/src/components/Slider/__tests__/Slider.test.tsx, packages/react-core/src/components/Slider/examples/SliderCustomTooltip.tsx, packages/react-core/src/components/Slider/examples/Slider.md
Adds hover and aria-valuetext tests, a SliderCustomTooltip example that maps step values to labels, and documentation for the new props.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Slider
  participant Thumb
  participant Tooltip
  Caller->>Slider: Pass tooltipContent and thumbAriaValueText
  Slider->>Thumb: Set aria-valuetext override
  Slider->>Tooltip: Set custom content when tooltip is enabled
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding custom tooltip content to Slider.
Linked Issues check ✅ Passed The PR delivers custom Slider tooltip content as requested in #12160, with docs and tests supporting the feature.
Out of Scope Changes check ✅ Passed The added accessibility prop and docs/tests still support the Slider tooltip feature and do not appear unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/react-core/src/components/Slider/Slider.tsx (1)

479-483: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use a nullish check for tooltipContent

tooltipContent is typed as React.ReactNode, so 0 and '' get ignored here and the tooltip falls back to findAriaTextValue(). Use tooltipContent !== undefined (or ??) instead of a truthiness check.

Proposed fix
-            content={tooltipContent ? tooltipContent : findAriaTextValue()}
+            content={tooltipContent !== undefined ? tooltipContent : findAriaTextValue()}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-core/src/components/Slider/Slider.tsx` around lines 479 - 483,
The Tooltip content selection in Slider should not use a truthiness check for
tooltipContent, since React.ReactNode can legitimately be 0 or an empty string.
Update the Tooltip rendering logic in Slider to use a nullish check (for
example, tooltipContent !== undefined or the nullish coalescing pattern) so
Tooltip receives tooltipContent whenever it is defined, and only falls back to
findAriaTextValue() when tooltipContent is actually undefined.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/react-core/src/components/Slider/Slider.tsx`:
- Around line 479-483: The Tooltip content selection in Slider should not use a
truthiness check for tooltipContent, since React.ReactNode can legitimately be 0
or an empty string. Update the Tooltip rendering logic in Slider to use a
nullish check (for example, tooltipContent !== undefined or the nullish
coalescing pattern) so Tooltip receives tooltipContent whenever it is defined,
and only falls back to findAriaTextValue() when tooltipContent is actually
undefined.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4240228-16d6-425e-9418-0b581c9cb8f4

📥 Commits

Reviewing files that changed from the base of the PR and between 8edf04a and 7b7ef1f.

📒 Files selected for processing (4)
  • packages/react-core/src/components/Slider/Slider.tsx
  • packages/react-core/src/components/Slider/__tests__/Slider.test.tsx
  • packages/react-core/src/components/Slider/examples/Slider.md
  • packages/react-core/src/components/Slider/examples/SliderCustomTooltip.tsx

@patternfly-build

patternfly-build commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

aria-valuetext={findAriaTextValue()}
aria-label={thumbAriaLabel}
aria-valuetext={thumbAriaValueText ? thumbAriaValueText : findAriaTextValue()}
aria-label={thumbAriaLabel ? thumbAriaLabel : thumbAriaLabel}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to use a different value for one of these?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember, I may have been thinking the default needed to be updated by the new prop but it doesn't. Reverted.

Comment thread packages/react-core/src/components/Slider/Slider.tsx Outdated
Comment thread packages/react-core/src/components/Slider/Slider.tsx Outdated
Comment thread packages/react-core/src/components/Slider/Slider.tsx
Comment thread packages/react-core/src/components/Slider/examples/Slider.md
Comment on lines +26 to +32
<Slider
hasTooltipOverThumb
tooltipContent={customTooltipContent()}
value={value}
onChange={(_event: SliderOnChangeEvent, value: number) => setValue(value)}
customSteps={steps}
/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be absolutely necessary with the above example verbiage added in, but we could add a second slider tothis example showing an implementation more similar to the original issue, where each step is a date timestamp. If we do, maybe we have the slider steps min and max values be 1-10 with whole number intervals

@kmcfaul
kmcfaul force-pushed the slider-custom-tooltip branch from 0255625 to b1d6f96 Compare July 20, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slider - custom tooltip

3 participants